package com.labichaoka.chaoka.ui.baseinfo.person_pip;

import com.labichaoka.chaoka.base.MyApplication;
import com.labichaoka.chaoka.entity.BaseResponse;
import com.labichaoka.chaoka.entity.SaveInformationRequest;
import com.labichaoka.chaoka.net.BaseSubscriber;
import com.labichaoka.chaoka.net.DataManager;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by ruan on 2018/8/13.
 */

public class PersonInfoPipInteractorImpl implements PersonInfoPipInteractor {
    private DataManager manager = new DataManager(MyApplication.mContext);
    private CompositeSubscription mCompositeSubscription = new CompositeSubscription();
    @Override
    public void saveInformation(SaveInformationRequest request, OnSaveInformationFinishedListener listener) {
        mCompositeSubscription.add(manager.saveInformation(request)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<BaseResponse>() {

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        listener.onSaveFailed();
                    }

                    @Override
                    public void onNext(BaseResponse response) {
                        super.onNext(response);
                        listener.onSaveSuccessed(response);
                    }
                })
        );
    }
}
